<%@ page import="com.xju.entity.User" %>
<%@ page import="com.xju.dao.OrderDao" %>
<%@ page import="com.xju.entity.Order" %>
<%@ page import="java.util.List" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>电子商务系统 - 我的订单</title>
  <link rel="stylesheet" type="text/css" href="static/css/style.css">
  <style>
    .order-list {
      display: flex;
      justify-content: center;
      flex-wrap: wrap;
      margin: 40px 0;
    }

    .order-item {
      border: 1px solid #ddd;
      margin: 20px;
      padding: 20px;
      width: 300px;
      text-align: center;
      background-color: rgba(255, 255, 255, 0.8); /* 半透明背景 */
      border-radius: 8px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    }

    .order-item h3 {
      margin: 10px 0;
    }

    .order-item p {
      margin: 5px 0;
    }
  </style>
</head>
<body>
<header>
  <h1>电子商务系统 - 我的订单</h1>
</header>
<main>
  <section class="order-list">
    <%
      HttpSession session1 = request.getSession();
      User user = (User) session1.getAttribute("user");
      if (user != null) {
        OrderDao orderDao = new OrderDao();
        List<Order> orders = orderDao.getOrdersByUserId(user.getId());
        request.setAttribute("orders", orders);
      }
    %>
    <c:if test="${not empty orders}">
      <c:forEach var="order" items="${orders}">
        <div class="order-item">
          <h3>订单号: ${order.id}</h3>
          <p>下单日期: ${order.order_date}</p>
          <p>总金额: $${order.total_price}</p>
          <p>状态: ${order.status}</p>
        </div>
      </c:forEach>
    </c:if>
    <c:if test="${empty orders}">
      <div class="order-item">
        <p>暂无订单记录</p>
      </div>
    </c:if>
  </section>
</main>
<footer>
  <p>&copy; 2023 电子商务系统. All rights reserved.</p>
</footer>
</body>
</html>
